import BEMHelper from 'react-bem-helper';

let getBEMHelperInstance = (name: string, prefix?: string) => {
  return new BEMHelper({
    name: name,
    prefix: prefix || 'rinvay-',
    outputIsString: true,
  });
};

let getDefaultObj = (extra?: string) => {
  return {
    element: '',
    modifiers: '',
    extra: extra || '',
  };
};

export const BEMClass = (block: string, extra?: string) => {
  const instance = getBEMHelperInstance(block);
  return (obj: object) => {
    const defaultObj = getDefaultObj(extra);
    return instance(Object.assign(defaultObj, obj));
  };
};

export const BEMClassPrefix = (BEMClass: {
  block: string;
  extra?: string;
  prefix?: string;
}) => {
  const instance = getBEMHelperInstance(BEMClass.block, BEMClass.prefix);
  return (obj: object) => {
    const defaultObj = getDefaultObj(BEMClass.extra);
    return instance(Object.assign(defaultObj, obj));
  };
};
